package com.qianbao.qianbaobusiness.ui.help;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.baseandroid.mvp.BaseMvpActivity;
import com.qianbao.qianbaobusiness.R;
import com.qianbao.qianbaobusiness.json.HelpBean;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * 帮助中心
 */
public class HelpCenterActivity extends BaseMvpActivity<HelpView, HelpPresenter>
        implements HelpView {

    @BindView(R.id.toolbar_back)
    RelativeLayout toolbarBack;     //返回
    @BindView(R.id.toolbar_title)
    TextView       toolbarTitle;      //标题
    @BindView(R.id.rv_helplist)
    RecyclerView   rvHelplist;    //帮助列表

    private String            mSceneId;   //
    private HelpCenterAdapter adapter;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_help;
    }

    @Override
    protected void initInject() {
        getActivityComponent().inject(this);
    }

    @Override
    protected void setupView() {
        toolbarTitle.setText(getApplicationContext().getResources().getString(R.string.help_center));
        LinearLayoutManager manager = new LinearLayoutManager(this);
        rvHelplist.setLayoutManager(manager);
        adapter = new HelpCenterAdapter(this);
        rvHelplist.setAdapter(adapter);
        View view = LayoutInflater.from(this).inflate(R.layout.layout_footer_help_center, null);
        TextView tv = view.findViewById(R.id.tv_help_nomsg);
        tv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(HelpCenterActivity.this, FeedBackActivity.class);
                Bundle b = new Bundle();
                b.putString("sceneId", mSceneId);
                intent.putExtra("bundle", b);
                startActivity(intent);
            }
        });
        adapter.setFooterView(view);
    }

    @Override
    protected void setupData(Bundle savedInstanceState) {
        mSceneId = getIntent().getStringExtra("sceneId");
        getPresenter().getHelpCenterListList();
    }

    @OnClick({R.id.toolbar_back})
    public void OnClick(View view) {
        switch (view.getId()) {
            case R.id.toolbar_back:
                finish();
                break;
            default:
                break;
        }
    }

    /**
     * 拉取帮助列表回调
     *
     * @param result
     */
    @Override
    public void onSuccess(HelpBean result) {
        adapter.resetData(result.getHelpList());
        adapter.notifyDataSetChanged();
    }
}
